<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
        promise 封装异步代码
        ① 将异步代码全部写到new Promise的回调函数（参数）中
        ② 异步代码中执行结果或者异常，都将使用 resolve 或 reject 传递到 then 或 catch 中处理
      */
      const p = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve(100);
        }, Math.random() * 1000);
      });
      p.then((data) => {
        console.log("then", data);
      });
    </script>
  </body>
</html>
